package com.bristua.mall.goods.biz;

import com.bristua.mall.common.bean.PageBean;
import com.bristua.mall.goods.dao.TUserEvaluateMapper2;
import com.bristua.mall.goods.model.TUserEvaluate2;
import com.bristua.mall.goods.model.condition.TUserEvaluateExample2;
import com.bristua.mall.goods.model.condition.queryGoodsEvalute.QueryGoodsEvalute;
import com.bristua.mall.goods.model.vo.QueryGoodsEvaluteVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/3/26.
 */
@Service
public class QueryGoodsEvaluteBiz {

    @Resource
    private TUserEvaluateMapper2 tUserEvaluateMapper2;

    public PageBean queryGoodsEvalute(QueryGoodsEvalute queryGoodsEvalute){

        TUserEvaluateExample2 tUserEvaluateExample = new TUserEvaluateExample2();
        tUserEvaluateExample.setOrderByClause("create_time desc");
        tUserEvaluateExample.createCriteria().andProductIdEqualTo(queryGoodsEvalute.getProductId());
        Page<TUserEvaluate2> objects = PageHelper.startPage(queryGoodsEvalute.getPageNo(),queryGoodsEvalute.getPageSize());
        List<TUserEvaluate2> tUserEvaluates = tUserEvaluateMapper2.selectByExample(tUserEvaluateExample);
        PageBean data = new PageBean<>(objects);
        if(data.getList()!=null && data.getList().size()>0){
            List<QueryGoodsEvaluteVO> queryGoodsEvaluteVOS = new ArrayList<>();
            for(int i=0;i<data.getList().size();i++){
                TUserEvaluate2 tUserEvaluate = (TUserEvaluate2) data.getList().get(i);
                QueryGoodsEvaluteVO queryGoodsEvaluteVO = new QueryGoodsEvaluteVO();
                BeanUtils.copyProperties(tUserEvaluate,queryGoodsEvaluteVO);
                queryGoodsEvaluteVOS.add(queryGoodsEvaluteVO);
//                tDevice.setIsOnline(DeviceCode.getValueByCode(Integer.valueOf(tDevice.getIsOnline())));
            }
            data.getList().clear();
            data.getList().addAll(queryGoodsEvaluteVOS);
        }
        return data;
    }
}
